<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Skornyakov Anatoliy
 * Date: 30.05.13
 * Time: 15:25
 * 
 */

class Zftest_Form extends Zend_Form
{
    private $_stackDecorators = array(
        'table' => array(
            'elements' => array(
                'ViewHelper',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
            ),
            'buttons' => array(
                'ViewHelper',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'button', 'colspan' => 2)),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
            ),
            'form' => array(
                'FormElements',
                 array('HtmlTag', array('tag' => 'table')),
                 'Form'
            )
    ));

    static public function callbackDecoratorGroup($content, $element, array $options)
    {
        return '<tr><td colspan="2"><b>' . $element->getLegend() . '</b><td></tr>' . $content;
    }

    public function getStackDecorators($type = 'table', $element = 'elements')
    {
        if (isset($this->_stackDecorators[$type]) && isset($this->_stackDecorators[$type][$element])) {
            return $this->_stackDecorators[$type][$element];
        } else {
            throw new Zend_Form_Exception(sprintf('Not found "%s" in stack decorators', $type . '-' . $element));
        }
    }
}